home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / rexx / 168 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.2 KB

  1. Path: mail2news.demon.co.uk!astrac1.demon.co.uk
  2. From: root <root@astrac1.demon.co.uk>
  3. Newsgroups: comp.lang.rexx
  4. Subject: Re: Newbie: numerics in REXX
  5. Date: Wed, 10 Jan 1996 12:12:12 GMT
  6. Organization: ASTRAC Ltd: IBM PC/mainframe EIS/MIS consultancy
  7. Message-ID: <1996Jan10.121212.269@astrac1.demon.co.uk>
  8. References: <DKBLIu.22B@rockyd.rockefeller.edu>
  9. X-NNTP-Posting-Host: astrac1.demon.co.uk
  10. X-Newsreader: TIN [version 1.2 PL2]
  11. X-Mail2News-Path: relay-4.mail.demon.net!post.demon.co.uk!astrac1.demon.co.uk
  12.  
  13. Dan Samber (dan@pendragon.rockefeller.edu) wrote:
  14. : OK. I'm having trouble adjusting to the fact that REXX has no variable 
  15. : types.... But in any case.... what I need to know is if there is a function
  16. : that will convert a string like 123 to actually be 123. As far as I can
  17. : tell saying 
  18.  
  19. : data = 123
  20.  
  21. : is equivalent to 
  22.  
  23. : data = "123"
  24.  
  25. : I know this since running
  26.  
  27. : data = 1
  28. : say data
  29. : outputs : 1
  30.  
  31. : produces different results then running
  32.  
  33. : data = "1"x  /* this is hex 1 same as decimal 1 or binary 1 */
  34. : say data
  35. : outputs a funcky character (it seems like its trying to print ASCII 1 which
  36. : is something funcky).
  37.  
  38. : I have tried all the c2d d2h etc.... and am losing my mind.
  39.  
  40. : Do I need to write a function that parses each character and subtracts
  41. : off the ASCII offset and multiply by 10^placeholder etc. or something
  42. : ugly like this????
  43.  
  44.  
  45.  
  46. : HELP ME!
  47.  
  48. : Thanks!
  49.  
  50.  
  51. : Dan
  52.  
  53. Dan, 
  54.  
  55. When I first started with REXX a few years ago, I had a massive
  56. battle with the c2{x,d} and {x,d}2c functions, and the way they
  57. relate to the difference between what is actually stored in the
  58. variables and what is printed on the screen.
  59.  
  60. Let's take d2c. 'c=d2c(45); say c' - after this, the variable c
  61. would contain the BINARY value 45 (presumably in one byte of
  62. storage), and 'say c' would cause whatever the character no.
  63. (decimal) 45 was in the table of printable characters (ASCII or
  64. EBCDIC) used on your system. (In ASCII, it's the hyphen.) On the
  65. other hand, 'd=45; say d' - on the screen are printed the ASCII
  66. representations of '4' and '5', and the variable d would be a
  67. string of bytes containing the ASCII values producing those two
  68. digits ('4' is 52 and '5' is 53.)
  69.  
  70. x2c works exactly the same, except that it uses hex strings
  71. rather than decimal numbers. For example 'c=x2c("2A"); say c': c
  72. contains the binary value 2A, and 'say c' would produce character
  73. no. 2A on the screen (in ASCII, according to my table, it would
  74. be "*".) On the other hand, after 'x=2A; say x', what would
  75. appear on the screen would be the characters representing 2 and A
  76. (ASCII (decimal) 50 and 65), and the actual value of x would be a
  77.  string of bytes containing the values 50 and 65.)
  78.  
  79. c2{d,x} work the other way: "c='2A'x; x=c2x(c); say x" - c has
  80. the binary value 2A; x is the string of bytes containing 50 and
  81. 65; on the screen are printed ASCII characters 50 and 65 - "2"
  82. and "A".
  83.  
  84. Does this make sense? I know what you mean about the feeling of
  85. going insane over this one - I've been there! I hope I've helped
  86. to clarify rather than re-muddy the waters: if the latter, or if
  87. I've screwed up any of the examples, then get back to me. 
  88. These functions are enormously powerful and flexible when they're 
  89. fully grasped.
  90.  
  91. Regards, 
  92. Peter
  93.  
  94.  
  95.  
  96.  
  97.